from rest_framework.views import APIView
from rest_framework.permissions import IsAdminUser, IsAuthenticated

from meiduo_admin.utils.pagination import MeiduoPagination
from users.models import User
from meiduo_admin.serializers.users import UserSerializer
from rest_framework.response import Response
from rest_framework import generics



class UsersView(generics.ListCreateAPIView):

    def get_queryset(self):
        queryset = User.objects.filter(is_staff=False)
        keyword = self.request.query_params.get('keyword')

        if keyword:
            queryset = queryset.filter(username__contains=keyword)

        queryset = queryset.order_by('-id')

        return queryset

    serializer_class = UserSerializer

    pagination_class = MeiduoPagination
